<template>
	<div style="margin: 20px;">
		<div>
      <tinymce :height="300" v-model="content"></tinymce>
    </div>
    <p v-if="permission == 3" style="text-align: center;"><el-button v-loading="btnLoading" type="primary" @click="save">保存</el-button></p>
	</div>
</template>
<script>
import { getAgentDesc, AgentDescSave } from '@/api/member'
import Tinymce from '@/components/Tinymce'
import { marketing_partner } from '@/utils/permission'
export default {
  name: 'tinymce-demo',
  components: { Tinymce },
  data() {
    return {
      btnLoading: false,
      permission: 3,
      companyId: null,
      content: null
    }
  },
  created() {
    this.getModelPermission()
    this.getList()
  },
  methods: {
    getModelPermission() {
      this.permission = marketing_partner()
    },
    getList() {
      getAgentDesc().then(res => {
        this.content = res.data.data.upgradeToAgentDesc
        this.companyId = res.data.data.companyId
      }).catch(err => {
        console.log(err)
      })
    },
    save() {
      if (this.btnLoading) {
        return
      }
      this.btnLoading = true
      var data = { data: { companyId: this.companyId, content: this.content }}
      AgentDescSave(data).then(res => {
        this.btnLoading = false
        this.$message({
          type: 'success',
          message: '设置成功!'
        })
      }).catch(err => {
        console.log(err)
        this.btnLoading = false
      })
    }
  }
}
</script>
<style>
</style>
